" 测试字符串内建函数
echo "Testing string built-in functions"

" 测试 len 函数
let s = "hello world"
echo "Length of '" . s . "': " . len(s)

" 测试 empty 函数
let empty_str = ""
let non_empty_str = "test"
echo "Is empty string empty? " . empty(empty_str)
echo "Is 'test' empty? " . empty(non_empty_str)

" 测试 stridx 函数
let text = "hello world hello"
echo "First occurrence of 'world' in '" . text . "': " . stridx(text, "world")
echo "First occurrence of 'hello' starting from position 2: " . stridx(text, "hello", 2)

" 测试 strridx 函数
echo "Last occurrence of 'hello' in '" . text . "': " . strridx(text, "hello")

" 测试 strpart 函数
echo "Substring from position 7: " . strpart(text, 7)
echo "Substring from position 1 with length 5: " . strpart(text, 1, 5)

" 测试 tolower 和 toupper 函数
let mixed_case = "HeLLo WoRLd"
echo "Lowercase: " . tolower(mixed_case)
echo "Uppercase: " . toupper(mixed_case)

" 测试 substitute 函数
let original = "hello world hello"
echo "Substitute first 'hello' with 'hi': " . substitute(original, "hello", "hi")
echo "Substitute all 'hello' with 'hi': " . substitute(original, "hello", "hi", "g")

" 测试 split 函数
let sentence = "hello world test"
echo "Split by whitespace: " . string(split(sentence))
echo "Split by 'o': " . string(split(sentence, "o"))

" 测试 join 函数
let words = ["hello", "world", "test"]
echo "Join with space: " . join(words)
echo "Join with comma: " . join(words, ",")

" 测试 string 函数
let num = 123
let bool_val = 1
echo "Number to string: " . string(num)
echo "Boolean to string: " . string(bool_val)